<template>
  <el-tabs v-model="activeName" type="card">
    <el-tab-pane v-for="item in data" :key="item.name" :lazy="true" :label="item.name" :name="item.name">
      <Java :value="item.content" :height="height" />
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import Java from '@/components/JavaEdit/index'
import { preview } from '@/api/generator'

export default {
  name: 'Previewer',
  props: ['tableName'],
  components: { Java },
  watch: {
    tableName: function() {
      this.refresh()
    }
  },
  data() {
    return {
      data: null, height: '', activeName: 'Entity'
    }
  },
  mounted() {
    this.height = document.documentElement.clientHeight - 180 + 'px'
    this.refresh()
  },
  methods: {
    refresh: function() {
      preview(this.tableName).then(data => {
        // this.data = deepClone(data)
        // this.data = null
        this.data = Object.assign({}, data)
      }).catch(() => {
        this.data = null
      })
    }
  }
}
</script>
